import Ember from 'ember';
import {
  modelNameFromRouteName,
  pluralModelNameFromRouteName
}
from 'emberworkspace/utils/app-util';

export default Ember.Mixin.create({
  tcName() {
    return pluralModelNameFromRouteName(this.get('routeName')) + "/edit";
  },
  renderTemplate() {
    var tcName = this.tcName();
      this.render( tcName, {
        controller: tcName
      });
    },
    setupController(controller, model) {
      var c = this.controllerFor(this.tcName());
      c.set('isNewRecord', true); //用来区分新建还是编辑。
      c.set('model', model);
    },
    model() {
      var modelName = modelNameFromRouteName(this.get('routeName'));
      return this.store.createRecord(modelName, {});
    }
});
